#include "sprite.h"

DECLARE_EXTERN_GLEXTENSIONS

extern GLint pos,texcoord,color;

namespace sprite{

texture::texture(){

	this->tex=0;
	this->SetSize(640,360);

}

texture::texture(int type, void* rec){

	this->SetSize(640,360);
	this->LoadTexture(type, rec);

}

texture::~texture(){

	glDeleteTextures(1,&this->tex);

}

void texture::LoadTexture(int type, void* rec){

	if(type==FILE_BITMAP){

		glPixelStorei(GL_UNPACK_ALIGNMENT,4);

		AUX_RGBImageRec* rec1=(AUX_RGBImageRec*)rec;

		glGenTextures(1,&this->tex);

		glBindTexture(GL_TEXTURE_2D,this->tex);

		this->SetSize((float)rec1->sizeX,(float)rec1->sizeY);
		
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_BASE_LEVEL,0);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL,4);
		glTexParameteri(GL_TEXTURE_2D,GL_GENERATE_MIPMAP_SGIS,GL_TRUE);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
		glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,rec1->sizeX,rec1->sizeY,0,GL_RGB,GL_UNSIGNED_BYTE,rec1->data);
		
	}

}

GLuint texture::GetTex() const{

	return this->tex;

}

void SetTextureParam(GLenum name,GLint param){
	
	glTexParameteri(GL_TEXTURE_2D,name,param);

	/*switch(name){
		case GL_TEXTURE_MIN_FILTER:
		case GL_TEXTURE_MAG_FILTER:
		case GL_TEXTURE_MIN_LOD:
		case GL_TEXTURE_MAX_LOD:
		case GL_TEXTURE_BASE_LEVEL:
			case
			case
			case
			case
			case
			case
			case
			case
			case
			case
			case
	}*/

}

}